from requests_html import HTMLSession
from constant.config import DOUBAN_MOVIE_INFO
import re
from util.redisQueue import RedisQueue
import json


class MovieInfoSpider(object):

    def __init__(self, movieName):
        '''
        初始化电影信息查询
        :param movieName: 需要查询的电影名字
        '''
        self.r = RedisQueue("movie_url")
        movieName = self.r.get_wait()
        self.session = HTMLSession()
        movie = json.loads(movieName[-1])
        print(movie)
        name = re.search(".*?《(.*?)》", movie['name'], re.S)
        self.url = "http://api.douban.com/v2/movie/search?q={}".format(name)

    def openHtml(self):
        response = self.session.get(self.url)
        print(response.content)

if __name__ == '__main__':
    MovieInfoSpider("").openHtml()